import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('bgMove')
export class bgMove extends Component {

    @property(Node)
    bg01: Node = null;

    @property(Node)
    bg02: Node = null;

    @property
    speed: number = 100;

    start() {

    }

    update(deltaTime: number) {
         //获取bg01的坐标信息
        let position01 = this.bg01.position;
        //给bg01重新复制，让他每帧动画都向下移动
        this.bg01.setPosition(position01.x, position01.y - this.speed * deltaTime,position01.z)
         //获取bg01的坐标信息
        let position02 = this.bg02.position;
         //给bg01重新复制，让他每帧动画都向下移动
        this.bg02.setPosition(position02.x, position02.y - this.speed * deltaTime,position02.z)

        //设置背景循环播放
        let p1 = this.bg01.position;
        let p2 = this.bg02.position;
        if(this.bg01.position.y<-1280){
            this.bg01.setPosition(p2.x,p2.y+1280,p2.z);
        }

        if(this.bg02.position.y<-1280){
            this.bg02.setPosition(p1.x,p1.y+1280,p1.z);
        }

    }
}

